# 这个文件用于检测数据库连接情况
import pymysql


def db_tst():
    db = pymysql.connect(
        host="127.0.0.1",
        user='root',
        password='root',
        database='dytt',
        port=3306
    )
    cursor = db.cursor()
    cursor.execute("select 1")
    data = cursor.fetchone()
    print(data)
    db.close()


def insert_db():
    db = pymysql.connect(
        host="127.0.0.1",
        user='root',
        password='root',
        database='dytt',
        port=3306
    )
    cursor = db.cursor()
    sql = """
    insert into film(
        id,name,date,pic,info,dlurl
      ) 
      values(1,'abc',2021,'http','abc','111111');
    """
    cursor.execute(sql)
    db.commit()
    db.close()

def is_db():
    db = pymysql.connect(
        host="127.0.0.1",
        user='root',
        password='root',
        database='dytt',
        port=3306
    )
    cursor = db.cursor()
    sql = """
    insert into user(
        id,username,gender,age,password
      ) 
      values(null,%s,%s,%s,%s);
    """
    cursor.execute(sql, ('spider', 1, 20, '222222'))
    db.commit()
    db.close()



if __name__ == '__main__':
    insert_db()
